import { log } from "console";

interface dataSourceType {
  [propName: string]: any;
}
// 手机号
const mobile = (_rule: dataSourceType, value: string, callback: () => {}, type = 'phone', msg = '请输入正确的手机号码', useValue: number = 0) => { // 手机号码验证
  if (_rule.required) {// 必填项验证非空并排除非必须项
    if (!useValue) { // 使用fullField校验
      if ((value === '' || value === null || value === undefined)) {
        return Promise.reject(`此项必填`);
      } else {
        const reg = /^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(16[2|6|7])|(18[0-9])|(17([0-1]|[3]|[5-8]))|(19[1|8|9]))\d{8}$/;
        return reg.test(value) ? Promise.resolve() : msg ? Promise.reject(`${'请输入正确的手机号码'}`) : Promise.reject(`${'请输入正确的手机号码'}`);
      }
    } else {
      if (!value || value == undefined) {
        return Promise.reject(`${'请输入正确的手机号码'}`);
      } else {
        const reg = /^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(16[2|6|7])|(18[0-9])|(17([0-1]|[3]|[5-8]))|(19[1|8|9]))\d{8}$/;
        return reg.test(value) ? Promise.resolve() : msg ? Promise.reject(`${'请输入正确的手机号码'}`) : Promise.reject(`${'请输入正确的手机号码'}`);
      }
    }
  } else {
    if (!useValue) {
      if ((value === '' || value === null || value === undefined)) {
        return Promise.resolve();
      } else {
        const reg = /^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(16[2|6|7])|(18[0-9])|(17([0-1]|[3]|[5-8]))|(19[1|8|9]))\d{8}$/;
        return reg.test(value) ? Promise.resolve() : msg ? Promise.reject(`${'请输入正确的手机号码'}`) : Promise.reject(`${'请输入正确的手机号码'}`);
      }
    } else {
      if (!value || value == undefined) {
        return Promise.resolve();
      } else {
        const reg = /^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(16[2|6|7])|(18[0-9])|(17([0-1]|[3]|[5-8]))|(19[1|8|9]))\d{8}$/;
        return reg.test(value) ? Promise.resolve() : msg ? Promise.reject(`${'请输入正确的手机号码'}`) : Promise.reject(`${'请输入正确的手机号码'}`);
      }
    }
  }
}

export default {
  component: {//展示型组件信息，每个组件的信息各不相同
    componentName: 'phone', // 组件名称
    settings: {// 对应的设置项， 可能不同组件设置也不尽相同。
      value: '',
      placeholder: '请输入',
      param: 'phone',
      rule: {
        required: true,
        validator: mobile,
        trigger: ["blur", "change"],
        msg1: '手机号不能为空！',
        msg2: '',
        api: "",
        key: 'siteDomain',
        params: {}, //校验传参
      },
      label: "手机号:",
      beforeText: '',
      afterText: '',
      api: "fetchOssNameUnique",
      width: 492,
      showCount: false,
      maxCount: 11,
      marginLeft: 32,
      marginTop: 0,
      helpMsg: '',
      type: 'textInput',
      associated: '',
      associatedValue: '',
    },
  }
}